package baduga.karo;

import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JLabel;


//klasa z domyślnym GUI stołu

import javax.swing.JOptionPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.Timer;

import java.awt.Font;

import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JMenuItem;
/**
* @author Karolina
*/
public class TableGame extends javax.swing.JFrame {

	private static final long serialVersionUID = 1L;
	
	//na czas testów to 1
	
	int dealerNumber = 5;
	
	//jak będzie true to pokazujemy all-in, fold itd...
	
	boolean myTurn = true;
	
	//ścieżka do plików graficznych - kart, ikonek itd
	
	
	
	private static Timer playerTimeToMove;
	
	
	protected static final String RESOURCE_DIR = "resources/";
	
	  private javax.swing.JButton jButtonAllIn;
	  private javax.swing.JButton jButtonBet;
	  private javax.swing.JButton jButtonCall;
	  private javax.swing.JButton jButtonCheck;
	  private javax.swing.JButton jButtonFold;
	  private javax.swing.JButton jButtonRaise;
	  private javax.swing.JButton jButtonSit;
	  private javax.swing.JButton jButtonStart;
	  private javax.swing.JLabel jLabel1;
	  protected javax.swing.JLabel jLabel10;
	  private javax.swing.JLabel jLabel11;
	  private javax.swing.JLabel jLabel12;
	  private javax.swing.JLabel jLabel13;
	  private javax.swing.JLabel jLabel14;
	  private javax.swing.JLabel jLabel15;
	  private javax.swing.JLabel jLabel16;
	  private javax.swing.JLabel jLabel17;
	  private javax.swing.JLabel jLabel18;
	  private javax.swing.JLabel jLabel19;
	  private javax.swing.JLabel jLabel20;
	  private javax.swing.JLabel jLabel21;
	  private javax.swing.JLabel jLabel22;
	  private javax.swing.JLabel jLabel23;
	  private javax.swing.JLabel jLabel24;
	  private javax.swing.JLabel jLabel25;
	  private javax.swing.JLabel jLabel26;
	  private javax.swing.JLabel jLabel27;
	  private javax.swing.JLabel jLabel28;
	  private javax.swing.JLabel jLabel29;
	  private javax.swing.JLabel jLabel30;
	  private javax.swing.JLabel jLabel31;
	  private javax.swing.JLabel jLabel32;
	  private javax.swing.JLabel jLabel33;
	  private javax.swing.JLabel jLabel34;
	  private javax.swing.JLabel jLabel35;
	  private javax.swing.JLabel jLabel36;
	  private javax.swing.JLabel jLabel37;
	  private javax.swing.JLabel jLabel38;
	  protected javax.swing.JLabel jLabel7;
	  protected javax.swing.JLabel jLabel8;
	  protected javax.swing.JLabel jLabel9;
	  private javax.swing.JMenuBar jMenuBar1;
	  private javax.swing.JMenu jMenuFIle;
	  private javax.swing.JMenu jMenuGame;
	  private javax.swing.JMenu jMenuHelp;
	  private javax.swing.JMenuItem jMenuItem1;
	  private javax.swing.JMenuItem jMenuItemAbout;
	  private javax.swing.JMenuItem jMenuItemExit;
	  private javax.swing.JMenuItem jMenuItemHelp;
	  private javax.swing.JMenuItem jMenuItemSit;
	  private javax.swing.JMenuItem jMenuItemStart;
	  private javax.swing.JPanel jPanel1;
	  private javax.swing.JPanel jPanel2;
	  private javax.swing.JPanel jPanel3;
	  private javax.swing.JPanel jPanel4;
	  private javax.swing.JPanel jPanel5;
	  private javax.swing.JPanel jPanel6;
	  private javax.swing.JPanel jPanel7;
	  private javax.swing.JPanel jPanel8;
	  private javax.swing.JScrollPane jScrollPane1;
	  private javax.swing.JTextArea jTextArea1;
	  private JLabel dealer1;
	  private JLabel dealer2;
	  private JLabel dealer3;
	  private JLabel dealer4;
	  private JLabel dealer6;
	  private JLabel dealer5;
	  public static JLabel lblCzasNaRuch = new JLabel("");
	 
	
	
	
	
	

  //tworzymy nowy stół
	
  public TableGame() {
  	setIconImage(Toolkit.getDefaultToolkit().getImage(TableGame.class.getResource("/baduga/karo/resources/icon.png")));
     
      initComponents();
       jButtonStart.setVisible(false);
       btnDealer.setVisible(false);
       jButtonAllIn.setEnabled(false);
       jButtonBet.setEnabled(false);
       jButtonCall.setEnabled(false);
       jButtonCheck.setEnabled(false);
       jButtonFold.setEnabled(false);
       jButtonRaise.setEnabled(false);
       btnDealer.setVisible(true);
       btnDealer.setEnabled(false);
       
       if(gameStart) {
    	   jMenuItemSit.setVisible(false);
    	   jMenuItemStart.setVisible(false);
    	   jButtonStart.setVisible(false);
    	   jButtonSit.setVisible(false);
       }
       
       if(dealerNumber == 6 && gameStart){
    	   btnDealer.setEnabled(true);
       }
       
       if(myTurn && gameStart) {
     	  jButtonAllIn.setEnabled(true);
     	  jButtonBet.setEnabled(true);
     	  jButtonCall.setEnabled(true);
     	  jButtonCheck.setEnabled(true);
     	  jButtonFold.setEnabled(true);
     	  jButtonRaise.setEnabled(true);
     	  btnNieWymieniam.setEnabled(true);
     	  
     	  
     	  
     	  //TODO: Czas będzie brany od serwera.
     	 /**
     	  * Odliczacz ile zostąłu do końca ruchu... gracza. Może do bankructwa?
     	  */
     	  
     	 //final Thread moveTimerThread = new Thread(new TimerThread(60, lblCzasNaRuch));
     	 //moveTimerThread.start();
     	 
     	 //playerTimeToMove.setInitialDelay(1000);
     	 playerTimeToMove.start();
     	  


     	  
   	     
       }
  }
  
  boolean playerSat = false;
  boolean wantsToPlay = false;
  //jak gra rozpoczeta to schowa przyciski "start" i "usiadz"
  boolean gameStart = true;
  
 
  
  
  @SuppressWarnings("unchecked")
  
  	//tworzymy podstawowe elementy graficzne stołu
  
  private void initComponents() {
      java.awt.GridBagConstraints gridBagConstraints;

      jMenuItem1 = new javax.swing.JMenuItem();
      jPanel1 = new javax.swing.JPanel();
      jLabel12 = new javax.swing.JLabel();
      jLabel16 = new javax.swing.JLabel();
      jLabel23 = new javax.swing.JLabel();
      jPanel2 = new javax.swing.JPanel();
      jLabel7 = new javax.swing.JLabel();
      jLabel9 = new javax.swing.JLabel();
      jLabel10 = new javax.swing.JLabel();
      jLabel8 = new javax.swing.JLabel();
      jPanel3 = new javax.swing.JPanel();
      jLabel13 = new javax.swing.JLabel();
      jLabel17 = new javax.swing.JLabel();
      jLabel22 = new javax.swing.JLabel();
      jPanel4 = new javax.swing.JPanel();
      jLabel14 = new javax.swing.JLabel();
      jLabel18 = new javax.swing.JLabel();
      jPanel5 = new javax.swing.JPanel();
      jLabel15 = new javax.swing.JLabel();
      jLabel19 = new javax.swing.JLabel();
      jLabel25 = new javax.swing.JLabel();
      jPanel6 = new javax.swing.JPanel();
      jLabel20 = new javax.swing.JLabel();
      jLabel21 = new javax.swing.JLabel();
      jLabel24 = new javax.swing.JLabel();
      jPanel7 = new javax.swing.JPanel();
      jLabel33 = new javax.swing.JLabel();
      jLabel32 = new javax.swing.JLabel();
      jLabel31 = new javax.swing.JLabel();
      jPanel8 = new javax.swing.JPanel();
      jLabel34 = new javax.swing.JLabel();
      jLabel35 = new javax.swing.JLabel();
      jLabel36 = new javax.swing.JLabel();
      jLabel38 = new javax.swing.JLabel();
      jLabel37 = new javax.swing.JLabel();
      jButtonAllIn = new javax.swing.JButton();
      jButtonRaise = new javax.swing.JButton();
      jButtonCheck = new javax.swing.JButton();
      jButtonFold = new javax.swing.JButton();
      jButtonCall = new javax.swing.JButton();
      jButtonBet = new javax.swing.JButton();
      jScrollPane1 = new javax.swing.JScrollPane();
      jLabel11 = new javax.swing.JLabel();
      jButtonSit = new javax.swing.JButton();
      jButtonStart = new javax.swing.JButton();
      jMenuBar1 = new javax.swing.JMenuBar();
      jMenuFIle = new javax.swing.JMenu();
      jMenuItemExit = new javax.swing.JMenuItem();
      jMenuGame = new javax.swing.JMenu();
      jMenuItemSit = new javax.swing.JMenuItem();
      jMenuItemStart = new javax.swing.JMenuItem();
      jMenuHelp = new javax.swing.JMenu();
      jMenuItemHelp = new javax.swing.JMenuItem();
      jMenuItemAbout = new javax.swing.JMenuItem();
      
      
      //rozmiary okna  i ustalenie rozmieszczenia elementów na stole
      //ułożenie graczy, ich nicków, stanów konta - cała szata graficzna gru
      
      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      setTitle("Badugi - Stół do gry");
      setMinimumSize(new java.awt.Dimension(900, 640));
      setPreferredSize(new java.awt.Dimension(900, 640));
      setResizable(false);
      setVisible(true);

      jLabel12.setFont(new java.awt.Font("Arial", 1, 14)); 
      jLabel12.setText("Player 3");

      jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource(RESOURCE_DIR + "card_back.png"))); 
      
      jLabel23.setText("123345 zł");
      dealer3 = new JLabel("New label");
      dealer3.setIcon(new ImageIcon(TableGame.class.getResource("/baduga/karo/resources/button_present.png")));
      dealer3.setVisible(false);
      jLabel26 = new javax.swing.JLabel();
      
            jLabel26.setFont(new java.awt.Font("Tahoma", 1, 11)); 
            jLabel26.setText("Włożył do puli x $");

      javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
      jPanel1Layout.setHorizontalGroup(
      	jPanel1Layout.createParallelGroup(Alignment.TRAILING)
      		.addGroup(jPanel1Layout.createSequentialGroup()
      			.addContainerGap(36, Short.MAX_VALUE)
      			.addGroup(jPanel1Layout.createParallelGroup(Alignment.TRAILING)
      				.addComponent(jLabel26, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
      				.addGroup(jPanel1Layout.createSequentialGroup()
      					.addComponent(dealer3, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING)
      						.addComponent(jLabel23, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE)
      						.addComponent(jLabel16)
      						.addComponent(jLabel12))))
      			.addGap(32))
      );
      jPanel1Layout.setVerticalGroup(
      	jPanel1Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel1Layout.createSequentialGroup()
      			.addContainerGap()
      			.addGroup(jPanel1Layout.createParallelGroup(Alignment.LEADING)
      				.addComponent(dealer3)
      				.addGroup(jPanel1Layout.createSequentialGroup()
      					.addComponent(jLabel12)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addGroup(jPanel1Layout.createParallelGroup(Alignment.TRAILING)
      						.addGroup(jPanel1Layout.createSequentialGroup()
      							.addComponent(jLabel16)
      							.addPreferredGap(ComponentPlacement.RELATED)
      							.addComponent(jLabel26, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
      							.addGap(159))
      						.addGroup(jPanel1Layout.createSequentialGroup()
      							.addComponent(jLabel23)
      							.addGap(290)))))
      			.addGap(159))
      );
      jPanel1.setLayout(jPanel1Layout);

      
      jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
              jLabel7MouseClicked(evt);
          }
      });

      
      jLabel9.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
              jLabel9MouseClicked(evt);
          }
      });

      
      jLabel10.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
              jLabel10MouseClicked(evt);
          }
      });

      
      jLabel8.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(java.awt.event.MouseEvent evt) {
              jLabel8MouseClicked(evt);
          }
      });

      javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
      jPanel2.setLayout(jPanel2Layout);
      jPanel2Layout.setHorizontalGroup(
          jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jPanel2Layout.createSequentialGroup()
              .addGap(0, 0, 0)
              .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGap(8, 8, 8)
              .addComponent(jLabel9)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
              .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
              .addComponent(jLabel8)
              .addContainerGap())
      );
      jPanel2Layout.setVerticalGroup(
          jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
              .addContainerGap()
              .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
              .addContainerGap())
          .addComponent(jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      );
      

      jLabel13.setText("99999&");

      jLabel17.setIcon(new javax.swing.ImageIcon(getClass().getResource(RESOURCE_DIR + "card_back.png"))); 

      jLabel22.setFont(new java.awt.Font("Arial", 1, 14));
      jLabel22.setText("Player 2");
      dealer2 = new JLabel("New label");
      dealer2.setIcon(new ImageIcon(TableGame.class.getResource("/baduga/karo/resources/button_present.png")));
      dealer2.setVisible(false);
      jLabel27 = new javax.swing.JLabel();
      
            jLabel27.setFont(new java.awt.Font("Tahoma", 1, 11)); 
            jLabel27.setText("Włożył do puli x $");

      javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
      jPanel3Layout.setHorizontalGroup(
      	jPanel3Layout.createParallelGroup(Alignment.TRAILING)
      		.addGroup(jPanel3Layout.createSequentialGroup()
      			.addContainerGap(21, Short.MAX_VALUE)
      			.addGroup(jPanel3Layout.createParallelGroup(Alignment.TRAILING)
      				.addComponent(jLabel27, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
      				.addGroup(jPanel3Layout.createSequentialGroup()
      					.addComponent(dealer2, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addGroup(jPanel3Layout.createParallelGroup(Alignment.LEADING)
      						.addComponent(jLabel13, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE)
      						.addComponent(jLabel17)
      						.addComponent(jLabel22))))
      			.addGap(19))
      );
      jPanel3Layout.setVerticalGroup(
      	jPanel3Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel3Layout.createSequentialGroup()
      			.addContainerGap()
      			.addGroup(jPanel3Layout.createParallelGroup(Alignment.LEADING)
      				.addGroup(jPanel3Layout.createSequentialGroup()
      					.addComponent(jLabel22)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addComponent(jLabel13)
      					.addGap(11)
      					.addComponent(jLabel17))
      				.addComponent(dealer2))
      			.addPreferredGap(ComponentPlacement.UNRELATED)
      			.addComponent(jLabel27, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
      			.addContainerGap(29, Short.MAX_VALUE))
      );
      jPanel3.setLayout(jPanel3Layout);

      jLabel14.setText("5000");

      jLabel18.setIcon(new javax.swing.ImageIcon(getClass().getResource(RESOURCE_DIR + "card_back.png"))); 
      
      
      
      dealer1 = new JLabel("New label");
      dealer1.setIcon(new ImageIcon(TableGame.class.getResource("/baduga/karo/resources/button_present.png")));
      dealer1.setVisible(false);
      dealer6 = new JLabel("New label");
      dealer6.setIcon(new ImageIcon(TableGame.class.getResource("/baduga/karo/resources/button_present.png")));
      dealer6.setVisible(false);
      jLabel1 = new javax.swing.JLabel();
      
            jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); 
            jLabel1.setText("Player 1");
      jLabel28 = new javax.swing.JLabel();
      
            jLabel28.setFont(new java.awt.Font("Tahoma", 1, 11)); 
            jLabel28.setText("Włożył do puli x $");
      
      
      
      
      javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
      jPanel4Layout.setHorizontalGroup(
      	jPanel4Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel4Layout.createSequentialGroup()
      			.addGap(16)
      			.addGroup(jPanel4Layout.createParallelGroup(Alignment.TRAILING)
      				.addComponent(jLabel28)
      				.addGroup(jPanel4Layout.createSequentialGroup()
      					.addComponent(dealer1, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
      					.addGap(12)
      					.addGroup(jPanel4Layout.createParallelGroup(Alignment.TRAILING)
      						.addComponent(jLabel1, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE)
      						.addGroup(jPanel4Layout.createParallelGroup(Alignment.LEADING)
      							.addComponent(jLabel14, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
      							.addComponent(jLabel18)))))
      			.addContainerGap(18, Short.MAX_VALUE))
      );
      jPanel4Layout.setVerticalGroup(
      	jPanel4Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel4Layout.createSequentialGroup()
      			.addContainerGap()
      			.addGroup(jPanel4Layout.createParallelGroup(Alignment.LEADING)
      				.addGroup(jPanel4Layout.createSequentialGroup()
      					.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addComponent(jLabel14)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addComponent(jLabel18))
      				.addComponent(dealer1))
      			.addPreferredGap(ComponentPlacement.RELATED)
      			.addComponent(jLabel28, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
      			.addContainerGap(34, Short.MAX_VALUE))
      );
      jPanel4.setLayout(jPanel4Layout);

      jLabel15.setFont(new java.awt.Font("Arial", 1, 14)); 
      jLabel15.setText("Player 5");

      jLabel19.setIcon(new javax.swing.ImageIcon(getClass().getResource(RESOURCE_DIR + "card_back.png"))); 

      jLabel25.setText("1,99zł");
      dealer5 = new JLabel("New label");
      dealer5.setIcon(new ImageIcon(TableGame.class.getResource("/baduga/karo/resources/button_present.png")));
      dealer5.setVisible(false);
      jLabel29 = new javax.swing.JLabel();
      
            jLabel29.setFont(new java.awt.Font("Tahoma", 1, 11)); 
            jLabel29.setText("Włożył do puli x $");

      javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
      jPanel5Layout.setHorizontalGroup(
      	jPanel5Layout.createParallelGroup(Alignment.TRAILING)
      		.addGroup(jPanel5Layout.createSequentialGroup()
      			.addGap(48)
      			.addGroup(jPanel5Layout.createParallelGroup(Alignment.TRAILING)
      				.addComponent(jLabel29)
      				.addComponent(jLabel19)
      				.addGroup(jPanel5Layout.createSequentialGroup()
      					.addComponent(dealer5, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
      					.addGap(10)
      					.addGroup(jPanel5Layout.createParallelGroup(Alignment.LEADING)
      						.addComponent(jLabel15, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)
      						.addComponent(jLabel25, GroupLayout.PREFERRED_SIZE, 70, GroupLayout.PREFERRED_SIZE))))
      			.addContainerGap(43, Short.MAX_VALUE))
      );
      jPanel5Layout.setVerticalGroup(
      	jPanel5Layout.createParallelGroup(Alignment.TRAILING)
      		.addGroup(jPanel5Layout.createSequentialGroup()
      			.addContainerGap(11, Short.MAX_VALUE)
      			.addGroup(jPanel5Layout.createParallelGroup(Alignment.LEADING)
      				.addGroup(jPanel5Layout.createSequentialGroup()
      					.addGap(23)
      					.addComponent(jLabel25)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addComponent(jLabel19))
      				.addComponent(jLabel15)
      				.addComponent(dealer5))
      			.addPreferredGap(ComponentPlacement.RELATED)
      			.addComponent(jLabel29, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
      			.addGap(27))
      );
      jPanel5.setLayout(jPanel5Layout);

      jLabel20.setFont(new java.awt.Font("Arial", 1, 14)); 
      jLabel20.setText("Player 4");

      jLabel21.setIcon(new javax.swing.ImageIcon(getClass().getResource(RESOURCE_DIR + "card_back.png"))); 

      jLabel24.setText("00000");
      dealer4 = new JLabel("New label");
      dealer4.setIcon(new ImageIcon(TableGame.class.getResource("/baduga/karo/resources/button_present.png")));
      dealer4.setVisible(false);
      jLabel30 = new javax.swing.JLabel();
      
            jLabel30.setFont(new java.awt.Font("Tahoma", 1, 11)); 
            jLabel30.setText("Włożył do puli x $");
            
      

      javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
      jPanel6Layout.setHorizontalGroup(
      	jPanel6Layout.createParallelGroup(Alignment.TRAILING)
      		.addGroup(jPanel6Layout.createSequentialGroup()
      			.addContainerGap(41, Short.MAX_VALUE)
      			.addGroup(jPanel6Layout.createParallelGroup(Alignment.TRAILING)
      				.addComponent(jLabel21)
      				.addComponent(jLabel30, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE)
      				.addGroup(jPanel6Layout.createSequentialGroup()
      					.addComponent(dealer4, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addGroup(jPanel6Layout.createParallelGroup(Alignment.LEADING)
      						.addComponent(jLabel20)
      						.addComponent(jLabel24, GroupLayout.PREFERRED_SIZE, 68, GroupLayout.PREFERRED_SIZE))))
      			.addGap(18))
      );
      jPanel6Layout.setVerticalGroup(
      	jPanel6Layout.createParallelGroup(Alignment.TRAILING)
      		.addGroup(jPanel6Layout.createSequentialGroup()
      			.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      			.addGroup(jPanel6Layout.createParallelGroup(Alignment.LEADING)
      				.addGroup(jPanel6Layout.createSequentialGroup()
      					.addGap(23)
      					.addComponent(jLabel24))
      				.addGroup(jPanel6Layout.createParallelGroup(Alignment.BASELINE)
      					.addComponent(jLabel20)
      					.addComponent(dealer4)))
      			.addPreferredGap(ComponentPlacement.RELATED)
      			.addComponent(jLabel21)
      			.addPreferredGap(ComponentPlacement.RELATED)
      			.addComponent(jLabel30, GroupLayout.PREFERRED_SIZE, 23, GroupLayout.PREFERRED_SIZE)
      			.addGap(35))
      );
      jPanel6.setLayout(jPanel6Layout);

      jPanel7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

      jLabel33.setText("Ilość rozdań: #");

      jLabel32.setText("Dealer: Gracz #");

      jLabel31.setText("Admin: Gracz#");

      javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
      jPanel7Layout.setHorizontalGroup(
      	jPanel7Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel7Layout.createSequentialGroup()
      			.addContainerGap()
      			.addGroup(jPanel7Layout.createParallelGroup(Alignment.LEADING)
      				.addComponent(jLabel33, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
      				.addComponent(jLabel31, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
      				.addComponent(jLabel32, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE))
      			.addContainerGap(37, Short.MAX_VALUE))
      );
      jPanel7Layout.setVerticalGroup(
      	jPanel7Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel7Layout.createSequentialGroup()
      			.addContainerGap()
      			.addComponent(jLabel33, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
      			.addPreferredGap(ComponentPlacement.RELATED)
      			.addComponent(jLabel32, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
      			.addPreferredGap(ComponentPlacement.RELATED)
      			.addComponent(jLabel31, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
      			.addContainerGap(20, Short.MAX_VALUE))
      );
      jPanel7.setLayout(jPanel7Layout);

      jPanel8.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

      jLabel34.setFont(new java.awt.Font("Arial", 1, 18)); 
      jLabel34.setText("Pula");

      jLabel35.setText("4358934765967943%");

      jLabel36.setFont(new java.awt.Font("Arial", 3, 12));
      jLabel36.setIcon(new javax.swing.ImageIcon(getClass().getResource(RESOURCE_DIR + "icon.png"))); 
      jLabel36.setText("BADUGI");
      jLabel36.setBorder(javax.swing.BorderFactory.createCompoundBorder());

      jLabel38.setText("Pozostały czas na ruch");

      chooseDealer(dealerNumber);
      
      //giveElapsedTime();
     
      
      
      
      javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
      jPanel8Layout.setHorizontalGroup(
      	jPanel8Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel8Layout.createSequentialGroup()
      			.addContainerGap()
      			.addGroup(jPanel8Layout.createParallelGroup(Alignment.LEADING)
      				.addGroup(Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
      					.addGap(0, 19, Short.MAX_VALUE)
      					.addGroup(jPanel8Layout.createParallelGroup(Alignment.TRAILING)
      						.addGroup(jPanel8Layout.createSequentialGroup()
      							.addComponent(jLabel34)
      							.addGap(42))
      						.addGroup(jPanel8Layout.createSequentialGroup()
      							.addComponent(jLabel36, GroupLayout.PREFERRED_SIZE, 91, GroupLayout.PREFERRED_SIZE)
      							.addContainerGap())))
      				.addGroup(Alignment.TRAILING, jPanel8Layout.createSequentialGroup()
      					.addComponent(jLabel35, GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
      					.addContainerGap())
      				.addGroup(jPanel8Layout.createSequentialGroup()
      					.addComponent(jLabel38, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      					.addContainerGap())
      				.addGroup(jPanel8Layout.createSequentialGroup()
      					.addComponent(lblCzasNaRuch, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)
      					.addContainerGap())))
      );
      jPanel8Layout.setVerticalGroup(
      	jPanel8Layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(jPanel8Layout.createSequentialGroup()
      			.addContainerGap(12, Short.MAX_VALUE)
      			.addComponent(jLabel36, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
      			.addPreferredGap(ComponentPlacement.UNRELATED)
      			.addComponent(jLabel34)
      			.addGap(1)
      			.addComponent(jLabel35, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
      			.addPreferredGap(ComponentPlacement.RELATED)
      			.addComponent(jLabel38, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
      			.addPreferredGap(ComponentPlacement.UNRELATED)
      			.addComponent(lblCzasNaRuch)
      			.addGap(21))
      );
      jPanel8.setLayout(jPanel8Layout);

      jLabel37.setFont(new java.awt.Font("Tahoma", 1, 11)); 
      jLabel37.setText("Włożyłeś do puli e $");

      //dopisanie akcji przyciskom odpowiadającym za najważniejsze akcje gry
      
      jButtonAllIn.setText("All-in");
      jButtonAllIn.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonAllInActionPerformed(evt);
          }
      });
     
      jButtonRaise.setText("Raise");
      jButtonRaise.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonRaiseActionPerformed(evt);
              
          }
      });

      jButtonCheck.setText("Check");
      jButtonCheck.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonCheckActionPerformed(evt);
          }
      });

      jButtonFold.setText("Fold");
      jButtonFold.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonFoldActionPerformed(evt);
          }
      });

      jButtonCall.setText("Call");
      jButtonCall.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonCallActionPerformed(evt);
          }
      });

      jButtonBet.setText("Bet");
      jButtonBet.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonBetActionPerformed(evt);
          }
      });

      jLabel11.setFont(new java.awt.Font("Arial", 1, 16)); 
      jLabel11.setText("Player 6");

      //przyciski "start" i "usiądź" - start pokazuje się dopiero jak ktoś usiądzie
      //"usiądź" wtedy znika
      
      jButtonSit.setText("Usiądź");
      jButtonSit.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonSitActionPerformed(evt);
          }
      });

      jMenuItemSit.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuItemSitActionPerformed(evt);
          }
      });
      
      jButtonStart.setText("START");
      jButtonStart.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jButtonStartActionPerformed(evt);
          }
      });
      
      jMenuItemStart.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuItemStartActionPerformed(evt);
          }
      });

      //obsługa menu pod paskiem tytułu i jego pozycji
      
      jMenuFIle.setText("Plik");

      jMenuItemExit.setText("Zakończ grę");
      jMenuItemExit.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuItemExitActionPerformed(evt);
          }
      });
      jMenuFIle.add(jMenuItemExit);

      jMenuBar1.add(jMenuFIle);

      jMenuGame.setText("Gra");

      jMenuItemSit.setText("Usiądź");
      jMenuGame.add(jMenuItemSit);

      jMenuItemStart.setText("Start");
      jMenuItemStart.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuItemStartActionPerformed(evt);
          }
      });
      jMenuGame.add(jMenuItemStart);
      jMenuItemStart.setEnabled(false);
      jMenuBar1.add(jMenuGame);
      
      mntmOpuSt = new JMenuItem("Opuść stół");
      mntmOpuSt.addActionListener(new ActionListener() {
    	  public void actionPerformed(java.awt.event.ActionEvent evt) {
              mntmOpuStActionPerformed(evt);
          }
      });
      
      jMenuGame.add(mntmOpuSt);

      jMenuHelp.setText("Help");

      jMenuItemHelp.setText("Help");
      jMenuItemHelp.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuItemHelpActionPerformed(evt);
          }
      });
      jMenuHelp.add(jMenuItemHelp);

      jMenuItemAbout.setText("About");
      jMenuItemAbout.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jMenuItemAboutActionPerformed(evt);
          }
      });
      jMenuHelp.add(jMenuItemAbout);

      jMenuBar1.add(jMenuHelp);

      setJMenuBar(jMenuBar1);
      //rozdaje karty
      btnDealer = new JButton("Rozdaj");
      
      btnDealer.addActionListener(new ActionListener() {
      	public void actionPerformed(ActionEvent arg0) {
      		
      	}
      });
      
      btnChangeCards = new JButton("Wymień");
      btnChangeCards.addActionListener(new ActionListener() {
      	public void actionPerformed(ActionEvent arg0) {
      		exchangeCards(accessMod);
      	}
      });
      btnChangeCards.setEnabled(false);
      
      btnNieWymieniam = new JButton("Nie wymieniam");
      btnNieWymieniam.setEnabled(false);
      

      
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      layout.setHorizontalGroup(
      	layout.createParallelGroup(Alignment.TRAILING)
      		.addGroup(layout.createSequentialGroup()
      			.addContainerGap()
      			.addGroup(layout.createParallelGroup(Alignment.LEADING)
      				.addGroup(layout.createSequentialGroup()
      					.addGroup(layout.createParallelGroup(Alignment.LEADING)
      						.addComponent(jPanel7, GroupLayout.PREFERRED_SIZE, 210, GroupLayout.PREFERRED_SIZE)
      						.addGroup(layout.createSequentialGroup()
      							.addGap(6)
      							.addGroup(layout.createParallelGroup(Alignment.LEADING)
      								.addGroup(layout.createSequentialGroup()
      									.addComponent(jButtonStart, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)
      									.addPreferredGap(ComponentPlacement.RELATED)
      									.addComponent(jButtonSit, GroupLayout.PREFERRED_SIZE, 105, GroupLayout.PREFERRED_SIZE))
      								.addGroup(layout.createSequentialGroup()
      									.addGroup(layout.createParallelGroup(Alignment.TRAILING)
      										.addComponent(jButtonAllIn, GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
      										.addComponent(jButtonCheck, GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
      										.addComponent(jButtonBet, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE))
      									.addPreferredGap(ComponentPlacement.RELATED)
      									.addGroup(layout.createParallelGroup(Alignment.LEADING)
      										.addComponent(jButtonFold, GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
      										.addComponent(jButtonRaise, GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)
      										.addComponent(jButtonCall, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE)))
      								.addComponent(btnDealer, GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))))
      					.addGap(18))
      				.addGroup(layout.createSequentialGroup()
      					.addComponent(jPanel5, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE)
      					.addPreferredGap(ComponentPlacement.RELATED)))
      			.addGroup(layout.createParallelGroup(Alignment.LEADING)
      				.addGroup(layout.createSequentialGroup()
      					.addGap(353)
      					.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 259, GroupLayout.PREFERRED_SIZE))
      				.addGroup(layout.createSequentialGroup()
      					.addGroup(layout.createParallelGroup(Alignment.TRAILING)
      						.addGroup(layout.createSequentialGroup()
      							.addGroup(layout.createParallelGroup(Alignment.LEADING)
      								.addGroup(layout.createSequentialGroup()
      									.addComponent(dealer6, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
      									.addPreferredGap(ComponentPlacement.UNRELATED)
      									.addComponent(jLabel11, GroupLayout.PREFERRED_SIZE, 69, GroupLayout.PREFERRED_SIZE))
      								.addComponent(jLabel37, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE))
      							.addPreferredGap(ComponentPlacement.UNRELATED)
      							.addGroup(layout.createParallelGroup(Alignment.TRAILING, false)
      								.addComponent(btnNieWymieniam, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      								.addComponent(btnChangeCards, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)))
      						.addGroup(layout.createParallelGroup(Alignment.LEADING)
      							.addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
      							.addGroup(layout.createSequentialGroup()
      								.addComponent(jPanel4, GroupLayout.PREFERRED_SIZE, 147, GroupLayout.PREFERRED_SIZE)
      								.addGap(18)
      								.addComponent(jPanel3, GroupLayout.PREFERRED_SIZE, 147, GroupLayout.PREFERRED_SIZE))))
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, 159, GroupLayout.PREFERRED_SIZE)
      					.addGap(18)
      					.addGroup(layout.createParallelGroup(Alignment.LEADING)
      						.addGroup(layout.createSequentialGroup()
      							.addComponent(jPanel6, 0, 0, Short.MAX_VALUE)
      							.addPreferredGap(ComponentPlacement.RELATED))
      						.addComponent(jPanel8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
      			.addGap(17))
      );
      layout.setVerticalGroup(
      	layout.createParallelGroup(Alignment.LEADING)
      		.addGroup(layout.createSequentialGroup()
      			.addContainerGap()
      			.addGroup(layout.createParallelGroup(Alignment.TRAILING)
      				.addGroup(layout.createSequentialGroup()
      					.addGroup(layout.createParallelGroup(Alignment.LEADING)
      						.addGroup(layout.createSequentialGroup()
      							.addGroup(layout.createParallelGroup(Alignment.LEADING)
      								.addComponent(jPanel7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
      								.addComponent(jPanel3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
      								.addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, 246, GroupLayout.PREFERRED_SIZE)
      								.addComponent(jPanel4, GroupLayout.PREFERRED_SIZE, 230, GroupLayout.PREFERRED_SIZE))
      							.addPreferredGap(ComponentPlacement.RELATED, 80, Short.MAX_VALUE)
      							.addGroup(layout.createParallelGroup(Alignment.TRAILING)
      								.addGroup(layout.createSequentialGroup()
      									.addGroup(layout.createParallelGroup(Alignment.TRAILING)
      										.addGroup(layout.createSequentialGroup()
      											.addComponent(btnDealer, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
      											.addPreferredGap(ComponentPlacement.UNRELATED)
      											.addGroup(layout.createParallelGroup(Alignment.BASELINE)
      												.addComponent(jButtonSit, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
      												.addComponent(jButtonStart, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)))
      										.addGroup(layout.createSequentialGroup()
      											.addGroup(layout.createParallelGroup(Alignment.BASELINE)
      												.addComponent(dealer6, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
      												.addComponent(jLabel11, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
      											.addPreferredGap(ComponentPlacement.RELATED)
      											.addComponent(jLabel37, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
      											.addPreferredGap(ComponentPlacement.RELATED)))
      									.addGap(4))
      								.addGroup(layout.createSequentialGroup()
      									.addComponent(btnNieWymieniam)
      									.addPreferredGap(ComponentPlacement.RELATED)
      									.addComponent(btnChangeCards))))
      						.addGroup(layout.createSequentialGroup()
      							.addComponent(jPanel8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
      							.addGap(18)
      							.addComponent(jPanel6, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE)))
      					.addPreferredGap(ComponentPlacement.RELATED)
      					.addGroup(layout.createParallelGroup(Alignment.TRAILING)
      						.addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 115, GroupLayout.PREFERRED_SIZE)
      						.addGroup(layout.createSequentialGroup()
      							.addGroup(layout.createParallelGroup(Alignment.TRAILING)
      								.addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
      								.addGroup(layout.createSequentialGroup()
      									.addGap(10)
      									.addGroup(layout.createParallelGroup(Alignment.BASELINE)
      										.addComponent(jButtonFold, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
      										.addComponent(jButtonAllIn, GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE))
      									.addGap(14)
      									.addGroup(layout.createParallelGroup(Alignment.BASELINE)
      										.addComponent(jButtonCall, GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
      										.addComponent(jButtonCheck, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE))
      									.addPreferredGap(ComponentPlacement.RELATED)
      									.addGroup(layout.createParallelGroup(Alignment.BASELINE)
      										.addComponent(jButtonRaise, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
      										.addComponent(jButtonBet, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE))))
      							.addGap(30)))
      					.addContainerGap())
      				.addGroup(layout.createSequentialGroup()
      					.addComponent(jPanel5, GroupLayout.PREFERRED_SIZE, 193, GroupLayout.PREFERRED_SIZE)
      					.addGap(264))))
      );
      jTextArea1 = new javax.swing.JTextArea();
      jTextArea1.setText("fdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdufdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdufdugffdgnsfdu fdugffdgnsfdu fdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdufdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdufdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdufdugffdgnsfdufdugffdgnsfdufdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdufdugffdgnsfdu fdugffdgnsfdufdugffdgnsfdu");
      jScrollPane1.setViewportView(jTextArea1);
      jTextArea1.setLineWrap(true);
      jTextArea1.setWrapStyleWord(true);
      
            //okienko komunikatów nt stanu rozgrywki
            
            jTextArea1.setColumns(20);
            jTextArea1.setFont(new Font("Arial", Font.PLAIN, 12));
            jTextArea1.setRows(5);
      getContentPane().setLayout(layout);

      pack();
  }
  
  //obsługa żądania wyjścia z menu

  private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {
      final ExitScreen question = new ExitScreen();
      question.setVisible(true);
      question.setLocationRelativeTo(null);    
      
      
      
      
      question.addWindowListener(
                      new java.awt.event.WindowAdapter() {
                          @Override
                          public void windowClosing(java.awt.event.WindowEvent e) {
                              final ExitScreen question = new ExitScreen();
                              question.setVisible(true);
                              question.setLocationRelativeTo(null);
                             
                              
                          }
                      }
              );
      
    

  }

  private void  mntmOpuStActionPerformed(java.awt.event.ActionEvent evt) {
		 Object[] options = {"Tak", "Nie"};
		  int exitChose = JOptionPane.showOptionDialog(null, 
		          "Na pewno chcesz wyjść?", 
		          "Wyjście", 
		          JOptionPane.YES_NO_OPTION, 0,null,options, options[1]); 
		  if (exitChose == JOptionPane.YES_OPTION) {
			 this.dispose();
		  	final TableListScreen guiTable = new TableListScreen();
		      guiTable.setVisible(true);
		      guiTable.setLocationRelativeTo(null);
		  	 }
	}
  //ustawiamy obrazek z literką "d" obok Dealera
  //dealerNumber = numer gracza, który jest dealerem
  //zakładam, że będzie jakaś tablica stringów z nazwami graczy i indeks właśnie będzie numerem
  
  public void chooseDealer(int dealerNumber){
  
  switch(dealerNumber) {
  case 1: dealer1.setVisible(true); break;
  case 2: dealer2.setVisible(true); break;
  case 3: dealer3.setVisible(true); break;
  case 4: dealer4.setVisible(true); break;
  case 5: dealer5.setVisible(true); break;
  case 6: dealer6.setVisible(true); break;
  default:;
  }
  }
  //wyswietlamy czas na ruch gracza

	 
	// public void giveElapsedTime(){
		 
// }
  
  //pozycje "pomoc" i "o autorach"

  private void jMenuItemHelpActionPerformed(java.awt.event.ActionEvent evt) {
      
  }

  private void jMenuItemAboutActionPerformed(java.awt.event.ActionEvent evt) {
      final AboutAuthorsScreen about = new AboutAuthorsScreen();
          about.setVisible(true);
          about.setLocationRelativeTo(null);
  }

  //informowanie serwera o zamiarach gracza - co nacisnął
  
  private void jMenuItemStartActionPerformed(java.awt.event.ActionEvent evt) {
      wantsToPlay = true;
      if(gameStart){
    	  jMenuItemStart.setEnabled(false);
    	  jButtonStart.setVisible(false);
    	    }
  }

 
  private void jButtonSitActionPerformed(java.awt.event.ActionEvent evt) {
      playerSat = true;
      jButtonStart.setVisible(true);
      jButtonSit.setVisible(false);
      jMenuItemStart.setEnabled(true);
      jMenuItemSit.setEnabled(false);
  }
  
  private void jMenuItemSitActionPerformed(java.awt.event.ActionEvent evt) {
      playerSat = true;
      jMenuItemStart.setEnabled(true);
      jMenuItemSit.setEnabled(false);
      jButtonStart.setVisible(true);
      jButtonSit.setVisible(false);
  }
  
  private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {
      wantsToPlay = true;
      if(gameStart){
    	  jMenuItemStart.setEnabled(false);
    	  jButtonStart.setVisible(false);
    	    }
  }
   
  
  //przyciski odpowiadające za rozgrywkę

  private void jButtonAllInActionPerformed(java.awt.event.ActionEvent evt) {
    
  }

  private void jButtonRaiseActionPerformed(java.awt.event.ActionEvent evt) {
	  
	  final Raise RaiseWindow = new Raise();
	  RaiseWindow.setVisible(true);
	  RaiseWindow.setLocationRelativeTo(null);

}   	  
    	  
      
  

  private void jButtonCheckActionPerformed(java.awt.event.ActionEvent evt) {
     
  }

  private void jButtonFoldActionPerformed(java.awt.event.ActionEvent evt) {
	  Object[] options = {"Tak", "Nie"};
	  int whatChose = JOptionPane.showOptionDialog(null, 
              "Na pewno chcesz spasować?", 
              "Potwierdzenie", 
              JOptionPane.YES_NO_OPTION, 0,null,options, options[1]); 
	  if (whatChose == JOptionPane.YES_OPTION) {
		   	//do zrobic gdy fold
		 }
	   
	    	
     
  }

  private void jButtonBetActionPerformed(java.awt.event.ActionEvent evt) {
     
  }

  private void jButtonCallActionPerformed(java.awt.event.ActionEvent evt) {
     
  }

   //metoda pozwalająca na wygodny wybór karty do wymiany
  //raz kliknięta karta wysuwa się
  //kliknięta drugi raz - chowa - i tak w kółko
  
  int[] accessMod = {1,1,1,1};
 
  
  
  
  
  private JButton btnDealer;
  int[] cardsToExchange = {-1, -1, -1, -1};
  private JButton btnChangeCards;
  int suma = 0;
  private JMenuItem mntmOpuSt;
  private JButton btnNieWymieniam;
  
  /**
   * Funkcja zajmującą się przesuwanie kart
   * 
   * 
   * @param index
   * @param label
   */
  synchronized void chooseCardsToExchange(int index, JLabel label) {
 
	if(this.myTurn)
	{
		
	  ;
		
	  if(accessMod[index] == 0) {
	      label.setLocation(label.getX(), label.getY() + 10);

	      accessMod[index] = 1;
	      suma -= accessMod[index];
	  }
	  	else
	  {
	      label.setLocation(label.getX(), (label.getY()) - 10);
	      
	      suma += accessMod[index];
	      accessMod[index] = 0;
	  } 
	  
	  
	  
	  
	  
	  
	  if(suma > 0)
		  btnChangeCards.setEnabled(true);
	  else
		  btnChangeCards.setEnabled(false);
	}
 

}

 
  //wywołujemy metodę dla pól jLabelów przeznaczonych na karty gracza
  //evt.getSource -> pobiera źródło żądania (Czyli skąd wyszło)
  
  private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {
      chooseCardsToExchange(0, (JLabel) evt.getSource());
  }

  private void jLabel9MouseClicked(java.awt.event.MouseEvent evt) {
      chooseCardsToExchange(1, (JLabel) evt.getSource());
  }

  private void jLabel10MouseClicked(java.awt.event.MouseEvent evt) {
      chooseCardsToExchange(2, (JLabel) evt.getSource());
  }

  private void jLabel8MouseClicked(java.awt.event.MouseEvent evt) {
      chooseCardsToExchange(3, (JLabel) evt.getSource());
  }

  // wysyłamy karty do wymiany - jeżeli accessMod[i] jest gdzieś równy 0 to znaczy że kart jest wysunięta
  // pod accessMod[0] mamy kartę umieszczoną w jLabel7, accessMod[1] to jLabel9, accessMod[2] to jLabel10, accessMod[3] to jLabel8
  
  public JLabel[] exchangeCards(int[] accessMod){
	  
	  JLabel[] cards = {null, null, null, null};
	  
	  for(int i = 0; i<= 3; i++){
		  if(accessMod[i] == 0) {
			  cardsToExchange[i] = i;
		  }
	  }
	  if(cardsToExchange[0] == 0)  
		  cards[0] = jLabel7;
	  if(cardsToExchange[1] == 1)  
		  cards[1] = jLabel9;
	  if(cardsToExchange[2] == 2)  
		  cards[2] = jLabel10;
	  if(cardsToExchange[3] == 3)  
		  cards[3] = jLabel8;
	  
	  return cards;
  }

  public static void main(String args[]) {
  	
	  
  	//zmieniamy styl okienek, jeżeli ten będzie niedostępny ładowany jest domyślny
      try {
          for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  javax.swing.UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
          java.util.logging.Logger.getLogger(Deck.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      }
      
      
      
      
  	 
      java.awt.EventQueue.invokeLater(new Runnable() {
          @Override
          public void run() {
        	  
        	  
        	  playerTimeToMove = new Timer(1000, new TimerThread(60, lblCzasNaRuch));

        	  
        	  
        	  //domyslne, pierwsze wywołanie z miejscem na kartę (do testów)
        	  // później jak przekażesz tablicę intów to wyświetli karty
        	  //swoją drogą czy ta funkcja nie nada się od razu do wyświetlania wymienionych kart?
             int[][] table = { {0, 0}, {0, 0}, {0, 0}, {0, 0}};
          	 Deck showingCards = new Deck();
          	 showingCards.setCards(table);
          	 showingCards.setLocationRelativeTo(null); 
          	 
          
       	  
          	 showingCards.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
             showingCards.addWindowListener(new java.awt.event.WindowAdapter() {
         });
  
      
             showingCards.addWindowListener(
                     new java.awt.event.WindowAdapter() {
                         @Override
                         public void windowClosing(java.awt.event.WindowEvent e) {
                             final ExitScreen question = new ExitScreen();
                             question.setVisible(true);
                             question.setLocationRelativeTo(null);
                           
                             
                         }
                     }
             );
             
             
         }
         
     });
             
             
        
  }
}



